﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Presentation.Models.Binders
{
    public class SubprojectViewModelBinding : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var model = base.BindModel(controllerContext, bindingContext) as SubprojectViewModel;
            var subproject = model.Subproject;

            foreach (var detail in model.Subproject.Details)
            {
                detail.Subproject = subproject;
            }

            return model;
        }
    }
}